<template>
	<div>
		<div>
			<el-input
				style="width: 300px; margin-right: 10px; margin-left: -500px;"
				clearable
				@clear="initPatient"
				v-model="name"
				@keydown.enter.native="initPatient"
			    placeholder="请输入姓名进行搜索"
			    prefix-icon="el-icon-search">
			</el-input>
			<el-button type="primary" @click="initPatient">搜索</el-button>
			<el-button type="primary" @click="showPatientAdd">添加</el-button>
		</div>
		<div>
			<el-table
		  :data="tableData"
			
			
		  style="width: 100%">
		   <el-table-column
		          prop="patientId"
		          label="序号"
		          >
		        </el-table-column>
		        <el-table-column
		          prop="name"
		          label="姓名"
		          >
		        </el-table-column>
		        <el-table-column
		          prop="sex"
		          label="性别">
		        </el-table-column>
				   <el-table-column
		      prop="age"
		      label="年龄"
		      >
		    </el-table-column>
		    <el-table-column
		      prop="idcard"
		      label="身份证号"
		      >
		    </el-table-column>
		    <el-table-column
		      prop="room"
		      label="房间号">
		    </el-table-column>
			   <el-table-column
		      prop="building"
		      label="所属楼房"
		      >
		    </el-table-column>
		  
		    <el-table-column
		      prop="indate"
		      label="入住时间">
		    </el-table-column>
			   <el-table-column
		      prop="outdate"
		      label="合同到期时间"
		      >
		    </el-table-column>
		    <el-table-column
		      prop="telphone"
		      label="联系电话"
		      >
		    </el-table-column>
		    
			  
			 
			  <el-table-column
			    prop="nurseId"
			    label="护工"
			    >
			  </el-table-column>
			  <el-table-column
			    prop="contact "
			    label="评估医生"
			    >
			  </el-table-column>
			 
		  <el-table-column label="操作">
		    <template slot-scope="scope">
		      <el-button @click="showPatientEdit(scope.row)">编辑</el-button>
		      	<el-button @click="deletePatient(scope.row)" type="danger">删除</el-button>
		    </template>
		  </el-table-column>
		</el-table>
		<el-pagination
			    background
				@current-change="currentChange"
			    layout="prev, pager, next,jumper,->,total"
			    :total=total>
			  </el-pagination>
		</div>
		 <el-dialog title="客户信息添加" :visible.sync="dialogVisible">
		 	<PatientAdd  :dialogVisible.sync=dialogVisible @add="initPatient()"></PatientAdd>
		 </el-dialog>
		 <el-dialog title="客户信息编辑" :visible.sync="editVisible">
		 			<PatientEdit :editVisible.sync="editVisible" :formData="formData"></PatientEdit>
		 		</el-dialog>
		</div>
		
		
		
	
</template>

<script>
	import PatientAdd from './patient_add.vue'
	import PatientEdit from './patient_edit.vue'
  export default {
	  name: "patient",
	  components:{
	  	PatientAdd,
		PatientEdit
	  },
	
    data(){
      return {
		  tableData:[],
		  total:0,
		  currentPage:1,
		  size:10,
		  name:'',
		  dialogVisible:false,
		  editVisible:false,
		  formData:{
			  patientId:'',
			  name:'',
			  sex:'',
			  age:'',
			  idcard:'',
			  birthday:'',
			  contact:'',
			  telphone:'',
			  address:'',
			  room:'',
			  building:'',
			  indate:'',
			  outdate:'',
			  remark:'',
			  nursingId:''
		  }
			  
		  }
		  
        
      },
	  
    
	mounted(){
		 this.initPatient();
	},
    methods: {
		showPatientEdit(data){
						this.editVisible=true;
						this.formData=data;
						// console.log("父组件数据:");
						// console.log(this.formData)
					},
		deletePatient(data){
						this.$confirm('此操作将永久删除'+data.patientId+'号病人的康复计划，是否继续？','提示',{
							confirmButtonText:'确定',
							cancelButtonText:'取消',
							type:'warning'
						}).then(() => {
							this.getRequest('/patient/delete?patientId='+data.patientId).then(resp =>{
								if(resp){
									this.initPatient();
								}
							})
						}).catch(() => {
							this.$message({
								type:'info',
								message:'已取消删除'
							});
						});
					},
		currentChange(currentPage){
			this.currentPage=currentPage;
			this.initPatient();
		},
		showPatientAdd(){
			this.dialogVisible=true
		},
		initPatient(){
			this.getRequest('/patient/planList?currentPage='+this.currentPage+'&size='+this.size+'&name='+this.name).then(resp=>{
				if(resp){         
					this.tableData=resp.data;
					this.total=resp.total;
				}
			})
		}
      
      }
    }
  
</script>

<style>
</style>
